package com.ssm.auth.infra.basic.service.impl;

import com.alibaba.fastjson.JSON;
import com.ssm.auth.infra.basic.entity.AuthRolePermission;
import com.ssm.auth.infra.basic.mapper.AuthRolePermissionDao;
import com.ssm.auth.infra.basic.service.AuthRolePermissionService;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 角色权限关联表(AuthRolePermission)表服务实现类
 *
 * @author makejava
 * @since 2024-12-13 10:07:40
 */
@Service("authRolePermissionService")
@Log4j2
public class AuthRolePermissionServiceImpl implements AuthRolePermissionService {
    @Resource
    private AuthRolePermissionDao authRolePermissionDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public AuthRolePermission queryById(Long id) {
        return this.authRolePermissionDao.queryById(id);
    }

    /**
     * 新增数据
     *
     * @param authRolePermission 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(AuthRolePermission authRolePermission) {
        if(log.isInfoEnabled()) {
            log.info("RolePermissionController.add.authRolePermission:{}", JSON.toJSONString(authRolePermission));
        }
        return this.authRolePermissionDao.insert(authRolePermission);
    }

    /**
     * 修改数据
     *
     * @param authRolePermission 实例对象
     * @return 实例对象
     */
    @Override
    public AuthRolePermission update(AuthRolePermission authRolePermission) {
        this.authRolePermissionDao.update(authRolePermission);
        return this.queryById(authRolePermission.getId());
    }

    /**
     * 批量插入
     * @param authRolePermissions
     * @return
     */
    @Override
    public int insertBatch(List<AuthRolePermission> authRolePermissions) {
        if(log.isInfoEnabled()) {
            log.info("RolePermissionController.add.authRolePermissions:{}", JSON.toJSONString(authRolePermissions));
        }
        return authRolePermissionDao.insertBatch(authRolePermissions);
    }

    /**
     * 查询
     * @param authRolePermission
     * @return
     */
    @Override
    public List<AuthRolePermission> queryByCondition(AuthRolePermission authRolePermission) {
        List<AuthRolePermission> authRolePermissions = authRolePermissionDao.queryByCondition(authRolePermission);
        if(log.isInfoEnabled()) {
            log.info("RolePermissionController.queryByCondition.authRolePermissions:{}", JSON.toJSONString(authRolePermissions));
        }
        return authRolePermissions;
    }

}
